package com.lewis.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lewis.core.annotation.Log;
import com.lewis.core.base.controller.BaseController;
import com.lewis.core.base.domain.BaseResult;
import com.lewis.core.base.page.TableDataInfo;
import com.lewis.core.enums.BusinessType;
import com.lewis.core.utils.office.excel.ExcelUtil;
import com.lewis.system.entity.SysLogOperational;
import com.lewis.system.service.ISysLogOperationalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author Lewis
 */
@Api(tags = "操作日志记录")
@RestController
@RequestMapping("/monitor/operlog")
public class SysLogOperationalController extends BaseController {

    @Resource
    private ISysLogOperationalService sysOperationalLogService;

    @ApiOperation(value = "查询日志列表")
    @GetMapping("/list")
    public TableDataInfo list(SysLogOperational sysLogOperational) {
        startPage();
        return getTableData(sysOperationalLogService.list(sysLogOperational));
    }

    @ApiOperation(value = "导出日志列表")
    @Log(title = "操作日志" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public BaseResult export(SysLogOperational operLog) {
        List<SysLogOperational> list = sysOperationalLogService.list(operLog);
        ExcelUtil<SysLogOperational> util = new ExcelUtil<SysLogOperational>(SysLogOperational.class);
        return util.exportExcel(list, "操作日志");
    }

    @ApiOperation(value = "批量删除日志")
    @Log(title = "操作日志" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public BaseResult remove(@PathVariable Long[] ids) {
        return getResult(sysOperationalLogService.removeByIds(Arrays.asList(ids)));
    }

    @ApiOperation(value = "清空日志列表")
    @Log(title = "操作日志" , businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public BaseResult clean() {
        return getResult(sysOperationalLogService.remove(new LambdaQueryWrapper<>()));
    }
}
